local RPDM = {}

// just a little temporary fix.
CreateClientConVar("sv_benchmark_force_start", 0, false, false)
CreateClientConVar("rpdm_showmessages", 1, true, false)
CreateClientConVar("rpdm_shownotify", 0, true, false)
CreateClientConVar("rpdm_messages_warningnotify", 1, true, false)
CreateClientConVar("rpdm_messages_dontshowincome", 0, true, false)
CreateClientConVar("rpdm_showsparks",1,true,false)
CreateClientConVar("rpdm_clcolor_r",255,true,true)
CreateClientConVar("rpdm_clcolor_g",255,true,true)
CreateClientConVar("rpdm_clcolor_b",255,true,true)
CreateClientConVar("rpdm_messages_r", 30, true, false)
CreateClientConVar("rpdm_messages_g", 30, true, false)
CreateClientConVar("rpdm_messages_b", 30, true, false)
CreateClientConVar("rpdm_messages_a", 100, true, false)
CreateClientConVar("rpdm_hints", 1, true, false)
CreateClientConVar("rpdm_autocomplete", 1, true, false)


function RPDM.MenuGet()
	spawnmenu.AddToolMenuOption("RPDM", "RPDM", "clPropAccess","Prop Protect","","",RPDM.AccessPanel)
	spawnmenu.AddToolMenuOption("RPDM", "RPDM", "clAllies","Allies","","",RPDM.AllyPanel)
	spawnmenu.AddToolMenuOption("RPDM", "RPDM", "clSettings","Settings","","",RPDM.OptionPanel)
	spawnmenu.AddToolMenuOption("RPDM", "RPDM", "clSettings2","Effect Settings","","",RPDM.OptionPanel2)
	spawnmenu.AddToolMenuOption("RPDM", "RPDM", "clCrosshair", "Crosshair Settings", "", "", RPDM.CrosshairOptions)
end
hook.Add("PopulateToolMenu", "RPDM_PopulateToolMenu", RPDM.MenuGet)

function RPDM.SpawnMenuOpen()
	if RPDM.OptionControlPanel then RPDM.OptionPanel(RPDM.OptionControlPanel) end
	if RPDM.OptionControlPanel2 then RPDM.OptionPanel2(RPDM.OptionControlPanel2) end
	if RPDM.AllyControlPanel then RPDM.AllyPanel(RPDM.AllyControlPanel) end
	if RPDM.AccessControlPanel then RPDM.AccessPanel(RPDM.AccessControlPanel) end
	if RPDM.AccessCross then RPDM.CrosshairOptions(RPDM.AccessCross) end
end
hook.Add("SpawnMenuOpen", "RPDM_SpawnMenuOpen", RPDM.SpawnMenuOpen)

RPDM.AccessCross = nil
function RPDM.CrosshairOptions(Panel)
	Panel:ClearControls()
	if RPDM.AccessCross==nil then RPDM.AccessCross=Panel end
	local CrosshairOptions = {Options = {}, CVars = {}, Label = "#Presets", MenuButton = "1", Folder = "mad_cows_crosshair"}
	CrosshairOptions.Options["#Default"] = {	mad_crosshair_r =	"114",
								mad_crosshair_g =	"255",
								mad_crosshair_b =	"0",
								mad_crosshair_a =	"200",
								mad_crosshair_l =	"30",
								mad_crosshair_t =	"1",
								mad_crosshair_d =	"1"
							   }
									
	CrosshairOptions.CVars = { 	"mad_crosshair_r",
						"mad_crosshair_g",
						"mad_crosshair_b",
						"mad_crosshair_a",
						"mad_crosshair_l",
						"mad_crosshair_t",
						"mad_crosshair_d"
					 }
						

	Panel:AddControl("CheckBox", {
		Label = "Enable Crosshair",
		Command = "mad_crosshair_t",
	})
	
	Panel:AddControl("CheckBox", {
		Label = "Dynamic Crosshair",
		Command = "mad_crosshair_d",
	})
	Panel:AddControl("CheckBox", {
		Label = "Slim Crosshair",
		Command = "mad_crosshair_thick",
	})

	Panel:AddControl("Color", {
		Label 	= "Crosshair Color",
		Red 		= "mad_crosshair_r",
		Green 	= "mad_crosshair_g",
		Blue 		= "mad_crosshair_b",
		Alpha 	= "mad_crosshair_a",
	})

	Panel:AddControl("Slider", {
		Label 	= "Crosshair Length",
		Command 	= "mad_crosshair_l",
		Type 		= "Integer",
		Min 		= "5",
		Max 		= "100",
	})
end

RPDM.OptionControlPanel = nil
function RPDM.OptionPanel(Panel)
	Panel:ClearControls()
	if RPDM.OptionControlPanel==nil then RPDM.OptionControlPanel=Panel end
	Panel:AddControl("Header", {Text="Messenger Options"})
	Panel:AddControl("CheckBox", {Label="Show Messenger", Command="rpdm_showmessages"})
	Panel:AddControl("CheckBox", {Label="Show Messages as notifications", Command="rpdm_shownotify"})
	Panel:AddControl("CheckBox", {Label="Show Warnings as notifications", Command="rpdm_messages_warningnotify"})
	Panel:AddControl("CheckBox", {Label="Don't show Income Messages", Command="rpdm_messages_dontshowincome"})
	Panel:AddControl("CheckBox", {Label="Show hints", Command="rpdm_hints"})
	Panel:AddControl("CheckBox", {Label="Show command suggestions", Command="rpdm_autocomplete"})
	Panel:AddControl("Color",  { Label	= "Message Colors",
									Red			= "rpdm_messages_r",
									Green		= "rpdm_messages_g",
									Blue		= "rpdm_messages_b",
									Alpha 		= "rpdm_messages_a",
									ShowAlpha	= 1,
									ShowHSV		= 1,
									ShowRGB 	= 1,
									Multiplier	= 255 })	
													

end

function RPDM.OptionPanel2(Panel)
	Panel:ClearControls()
	if RPDM.OptionControlPanel2==nil then RPDM.OptionControlPanel2=Panel end
									
	Panel:AddControl("Header", {Text="Effect Options"})
	Panel:AddControl("CheckBox", {Label="Show spark effects", Command="rpdm_showsparks"})
	if LocalPlayer():GetInfo("rpdm_clcolor_r")==nil then
		CreateClientConVar("rpdm_clcolor_r",255,true,true)
	end
	if LocalPlayer():GetInfo("rpdm_clcolor_g")==nil then
		CreateClientConVar("rpdm_clcolor_g",255,true,true)
	end
	if LocalPlayer():GetInfo("rpdm_clcolor_b")==nil then
		CreateClientConVar("rpdm_clcolor_b",255,true,true)
	end
	Panel:AddControl("Color",  { Label	= "Effect Colors",
									Red			= "rpdm_clcolor_r",
									Green		= "rpdm_clcolor_g",
									Blue		= "rpdm_clcolor_b",
									ShowAlpha	= 0,
									ShowHSV		= 1,
									ShowRGB 	= 1,
									Multiplier	= 255 })					

end

RPDM.AllyPanel = nil
function RPDM.AllyPanel(Panel)
	Panel:ClearControls()
	if RPDM.AllyControlPanel==nil then RPDM.AllyControlPanel=Panel end
	
	Panel:AddControl("Header", {Text="Allies"})
	for k, v in pairs(player.GetAll()) do
		if v!=LocalPlayer() then
		if LocalPlayer():GetInfo("rpdm_ally_"..v:UniqueID())==nil then
			CreateClientConVar("rpdm_ally_"..v:UniqueID(), 0, false, true)
		end
		Panel:AddControl("CheckBox", {Label=v:GetName(), Command="rpdm_ally_"..v:UniqueID()})
		end
	end
	
end

function RPDM.AccessPanel(Panel)
	Panel:ClearControls()
	if RPDM.AccessControlPanel==nil then RPDM.AccessControlPanel=Panel end
	
	Panel:AddControl("Header", {Text="Prop Protect"})
	if LocalPlayer():IsAdmin() || LocalPlayer():IsSuperAdmin() then
		Panel:AddControl("Button", {Label="Clear disconnected player props", Command="propprotect_clearoldprops"})
		Panel:AddControl("Button", {Label="Toggle admin prop protection", Command="propprotect_admin"})
	end
	for k, v in pairs(player.GetAll()) do
		if v!=LocalPlayer() then
			if LocalPlayer():GetInfo("propprotect_access_"..v:UniqueID())==nil then
				CreateClientConVar("propprotect_access_"..v:UniqueID(), 0, false, true)
			end
			Panel:AddControl("CheckBox", {Label=v:GetName(), Command="propprotect_access_"..v:UniqueID()})
		end
	end
	
end

function MakeAddToolMenuTabs()
    spawnmenu.AddToolTab("RPDM", "RPDM")
end
hook.Add("AddToolMenuTabs", "MakeAddToolMenuTabs", MakeAddToolMenuTabs)